<style type="text/css">
.table tr{
	height:62px;
}
</style>
<div class="table-responsive">
  <div class="filter-bar">
	<form action="__CONTROLLER__/index" method="post" >
		<div class="view">
			<div class="row clearfix">
				<div class="col-md-3 column ui-sortable">
				    <label class="col-sm-3 control-label">OPENID</label>
				    <div class="col-sm-9">
				      <input type="text" id="openId" class="form-control" name="openId" placeholder="" value="{$params.openId}">
				    </div>
				</div>
				
				<div class="col-md-3 column ui-sortable">
				    <label class="col-sm-3 control-label">昵称</label>
				    <div class="col-sm-9">
				      <input type="text" id="nickname" class="form-control" name="nickname" placeholder="" value="{$params.nickname}">
				    </div>
				</div>
				
				<div class="col-md-3 column ui-sortable">
				    <label class="col-sm-3 control-label">用户类型</label>
				    <div class="col-sm-9">
				      <select id="nickname" class="form-control" name="type">
				      {$UserTypesOptions}
				      </select>
				    </div>
				</div>
				
				<div class="col-md-3 column ui-sortable">
				    <div class="col-sm-9">
				       <input type="submit" class="btn btn-info submit" value="搜索"/>
				    </div>
				</div>
			</div>
		</div>
	</form>
  </div>
  <hr/>
  <table class="table table-hover">
    <thead>
      <tr>
        <th width="10%">ID</th>
        <th width="20%">OPENID</th>
        <th>用户</th>
        <th>等级</th>
        <th>积分</th>
        <th>已提积分</th>
        <th>推荐人</th>
        <th>加入时间/最后登入时间/成为金牌会员时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
    <volist name="wechatUserLists" id="vo">
      <tr>
        <td>{$vo.id}</td>
        <td>{$vo.openId}</td>
        <td>
        	<img src="{$vo['face']}" width="45" height="45" />
        	{$vo['nickname']?$vo['nickname']:'游客'}
        </td>
        <td>
        	{$vo['showRoles']}
        </td>
        <td>{$vo.bonus}</td>
        <td>{$vo.mention}</td>
        <td>
        	<if condition="$vo['referee']">
        	<img src="{$vo['referee']['face']}" width="45" height="45" />
        	{$vo['referee']['nickname']?$vo['referee']['nickname']:'游客'}
        	<else/>
        	无人推荐
        	</if>
        </td>
        <td>
	        <if condition="$vo['createTime']">{$vo['createTime']|date='Y-m-d H:i:s',###}<else/>-</if>
	        <br/>
	        <if condition="$vo['lastLoginTime']">{$vo['lastLoginTime']|date='Y-m-d H:i:s',###}<else/>-</if>
	        <br/>
	        <if condition="$vo['dealerTime']">{$vo['dealerTime']|date='Y-m-d H:i:s',###}<else/>-</if>
        </td>
        <td>
         <php>
         if( !in_array(1, $vo['roles']) ) {
         </php>
          <a class="btn btn-primary btn-xs" href="{:U('Agent/add', 'wechat_uid='.$vo['id'])}">加为代理商</a>
         <php>
         }
         </php>
        
         <php>
         if( !in_array(2, $vo['roles']) ) {
         </php>
          <a class="btn btn-primary btn-xs" href="{:U('Dealer/add', 'wechat_uid='.$vo['id'])}">加为金牌会员</a>
         <php>
         }
         </php>
        
         <php>
         if( in_array(2, $vo['roles']) ) {
         </php>
          <a class="btn btn-primary btn-xs" href="__CONTROLLER__/editInfo/id/{$vo['id']}">金牌会员信息</a>
          <a class="btn btn-primary btn-xs btn-cancel-dealer" href="javascript:return false;" uid="{$vo['id']}">取消金牌会员</a>
          <a class="btn btn-primary btn-xs" href="__CONTROLLER__/certificate/id/{$vo['id']}">金牌会员证书</a>
         <php>
         }
         </php>
         <a class="btn btn-primary btn-xs" href="{:U('DistributionShopWechatUser/userTree', 'id='.$vo['id'])}">查看下线({$vo.sonCount}/{$vo.subCount})</a>
         <a class="btn btn-primary btn-xs" href="{:U('DistributionShopOrder/showUserOrderList', 'uid='.$vo['id'])}">分销订单</a>
        </td>
      </tr>
    </volist>
    </tbody>
  </table>
</div>
<div class="pagination">{$pagination}</div>
<script type="text/javascript">
$(function() {
	$(".btn-cancel-dealer").click(function() {
		if ( confirm("确定要解除金牌会员资格吗?") ) {
			var othis = $(this), id = othis.attr("uid");
			
			$.ajax({
				type: "POST",
				url: "__CONTROLLER__/removeDealer",
				data: {
					id: id
				},
				beforeSend: function() {
					othis.attr("disabled", true);
				},
				success: function(data) {
					if (data.error == 0) {
						$().alertMsg({
							type: 'success',
							msg: data.msg
						});
						location.reload();
					} else {
						$().alertMsg({
							type: 'danger',
							msg: data.msg
						});
					}
				},
				error: function() {
					$().alertMsg({
						type: 'danger',
						msg: '网络错误，请重试！'
					});
				},
				complete: function() {
					othis.removeAttr('disabled');
				}
			});
		}
	});
});
</script>